package com.link.base.base.user.controller;

import com.link.core.basic.interceptor.SecurityInterceptor;
import com.link.core.util.RedisUtil;
import com.link.core.util.redisclient.LinkRedisClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author HuangLJ
 * @throws Exception
 * @Date 2018/9/6 下午4:41
 * @Comments 退出函数，当退出之后，删除当前的token
 */
@Controller
@RequestMapping("/link/token")
public class TokenManageController {


    @RequestMapping(value = "/remove")
    public Map<String, Object> remove(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        LinkRedisClient jedis = RedisUtil.getJedis();
        try {

            String token = SecurityInterceptor.token.get();
            jedis.del("access:" + token);
            jedis.del("access_to_refresh:" + token);
            jedis.del("auth:" + token);
            jedis.del("auth_user_" + token);
            jedis.del("login_info_" + token);

            result.put("success", true);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", e.getMessage());
        } finally {
            RedisUtil.returnResource(jedis);
        }
        return result;
    }

}
